package 链表;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

/**
 * @author Kevin
 * @Data 2021/2/19
 */

public class LinkList {
    public static void main(String[] args) {
        String s = "aanrakjvyjdmwkgyknrbtarcuiymxgltnefhxzebzfwuvjhudnbhssysbhvwqgsbkhzayquhhamlfkevbrmvuxlxnrmnnhkctckktvcirkvbbcndxuqojlsvxvgfslkukcsplxalfscreenyzziwahyohelaotyvriaalkyhcatmiwlduwpewljjihkebpuawfemolgiitoljqyizkfeimvjdqpxiiwfnrjblnzxywyicmuckrzvxwxpdqqkrkjuohtuuthoujkrkqqdpxwxvzrkcumciywyxznlbjrnfwiixpqdjvmiefkziyqjlotiiglomefwaupbekhijjlwepwudlwimtachyklaairvytoalehoyhawizzyneercsflaxlpsckuklsfgvxvsljoquxdncbbvkricvtkkctckhnnmrnxlxuvmrbvekflmahhuqyazhkbsgqwvhbsysshbnduhjvuwfzbezxhfentlgxmyiucratbrnkygkwmdjyvjkarnaa";
        System.out.println(judgeString(s));
    }
    public static String judgeString(String s ) {
        if(s.length()<2){
            return s;
        }
        int maxNumString = s.length()*(s.length()+1)/2;
        int[] maxNum = new int[maxNumString];
        Map<Integer,String> map = new HashMap<>();
        for (int i = 0; i < s.length(); i++) {
            for (int j = i+1; j <= s.length(); j++) {
                int l = lengthString(s.substring(i,j),0,s.substring(i,j).length()-1);
                map.put(l,s.substring(i,j));
              System.out.println(s.substring(i,j));
            }
        }
        Iterator<Integer> iter = map.keySet().iterator();
        int k =0;
        while (iter.hasNext()){
            maxNum[k] = iter.next();
            k++;
        }
        int max = 0;
        for (int i = k; i > 0; i--) {

             if (maxNum[i] < maxNum[i-1]){
                 int temp;
                 max = maxNum[i-1];
//                 temp = max ;
//                 max = maxNum[i-1];
//                 maxNum[i-1] = temp;
             }
        }
        return map.get(max);
    }

    public static int lengthString(String s,int left ,int right){
        int r =right;
        while(left <= right && s.charAt(left) == s.charAt(right)){
            left ++ ;
            right -- ;
        }
        if(left > right){
            return r + 1;
        }else{
            return 1;
        }
    }
}
